{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b41b69ec",
   "metadata": {},
   "source": [
    "-------\n",
    "* 2022/09/13/week04\n",
    "* python课堂笔记\n",
    "------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "630dadae",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## 上周回顾（range（））:range范围\n",
    "range(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "644ba612",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "# for + range 决定循环的次数\n",
    "for i in range(5): \n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "12cb3514",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 10, 3)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,10,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "17a5db4e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "4\n",
      "7\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,10,3):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7a0b96c8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 5)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b4251971",
   "metadata": {},
   "outputs": [],
   "source": [
    "# start? stop? step?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "851d0470",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "\n",
    "* type():检查类型\n",
    "\n",
    "> 1. 数值\n",
    ">> 1. int 整数\n",
    ">> 2. folat 浮点数\n",
    ">> 3. complex 复数,虚数\n",
    "\n",
    "> 2. 字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5c45f8a8",
   "metadata": {},
   "source": [
    "## 1.数值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "28c1e22f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "## Number（数值）\n",
    "## int 整数\n",
    "a = 9\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "63debe67",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11.5 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "## float 浮点数（虚数）\n",
    "b = 11.5\n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "1f654134",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(5+3j) <class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "## complex(虚数，复数)\n",
    "c = 5 + 3j\n",
    "print(c,type(c))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bdbf7f5a",
   "metadata": {},
   "source": [
    "## 2.字符串(string)\n",
    "\n",
    "> 1. 关于字符串的基本内容\n",
    "> 2. 关于字符串的方法及函数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6dc6cb72",
   "metadata": {},
   "source": [
    "### 2.1关于字符串的基本内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "3dca09bc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = \"Alex\"\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "1bff022e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "72448e90",
   "metadata": {},
   "outputs": [],
   "source": [
    "nfu_news_pages_html =  \n",
    "\"\"\"\n",
    "\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "70e61335",
   "metadata": {},
   "source": [
    "### 2.2关于字符串的方法及函数\n",
    "\n",
    "> 1. 字符串的定义\n",
    ">> 1. \n",
    ">> 2. \n",
    ">> 3. \n",
    "> 2. 字符串的拼接\n",
    "> 3. \n",
    "> 4. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "142b4e36",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州南方学院坐落于广州市从化温泉镇\n"
     ]
    }
   ],
   "source": [
    "# 关于有序性\n",
    "title = \"广州南方学院坐落于广州市从化温泉镇\"\n",
    "print(title)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "d1b105c9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0] # 取单一值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "d0147c85",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'州'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[1] # 取单一值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "7a86c3ad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "17"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(title) # 检查文本的总长度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "71f5abb3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'镇'"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[-1] # 取单一值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "8ea795a0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0:6] # 取一定范围的值，这种方法我们称其为\"切片\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "8e246e27",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6b7051ee",
   "metadata": {},
   "outputs": [],
   "source": [
    "## enumerate 枚举，既可以获取到这个内容item，又可以获取到索引值index。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "a4e09ef3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 广\n",
      "1 州\n",
      "2 南\n",
      "3 方\n",
      "4 学\n",
      "5 院\n",
      "6 坐\n",
      "7 落\n",
      "8 于\n",
      "9 广\n",
      "10 州\n",
      "11 市\n",
      "12 从\n",
      "13 化\n",
      "14 温\n",
      "15 泉\n",
      "16 镇\n"
     ]
    }
   ],
   "source": [
    "## 利用for循环，遍历文本信息\n",
    "for i,j in enumerate(title):\n",
    "    print(i,j)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "d2e97afb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州这个词在这段文本中\n",
      "广州这个词在这段文本中\n"
     ]
    }
   ],
   "source": [
    "# 思考：如何判断一段文本中是否存在“广州”，例如文本 title 中的内容\n",
    "\n",
    "for i,j in enumerate(title):\n",
    "    if j == \"广\":\n",
    "       if title[i+1] == \"州\":\n",
    "            print(\"广州这个词在这段文本中\")\n",
    "            "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cc65ad4d",
   "metadata": {},
   "source": [
    "### 2.3 page59  in 检查成员对象"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "3865431c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## page59  in 检查成员对象（可以检查是否在其中）\n",
    "\"广州\" in title"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9a912dcb",
   "metadata": {},
   "source": [
    "* 字符串的拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "8347e89a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好,Alex\n"
     ]
    }
   ],
   "source": [
    "print(\"你好\" + \",\" +  \"Alex\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "f7002b72",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "can only concatenate str (not \"int\") to str",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [44]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;66;03m# 字符串不可以跟数字进行连接\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m你好\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m1\u001b[39;49m \u001b[38;5;241m+\u001b[39m  \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAlex\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
      "\u001b[1;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str"
     ]
    }
   ],
   "source": [
    "# 字符串不可以跟数字进行连接\n",
    "print(\"你好\" + 1 +  \"Alex\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "f8e1e294",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 <class 'int'>\n",
      "1 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(1,type(1))\n",
    "print(\"1\",type(\"1\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "6055c28f",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "unsupported operand type(s) for /: 'str' and 'str'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [45]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;66;03m# 字符串不可以用来运算\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m3\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m2\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n",
      "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for /: 'str' and 'str'"
     ]
    }
   ],
   "source": [
    "# 字符串不可以用来运算\n",
    "\"3\"/\"2\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "0e619630",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 由于分不清数值和字符串闹出来的笑话（以下为正确的，不正确的是给数字加引号）\n",
    "width = 16\n",
    "height = 9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "d34826fd",
   "metadata": {},
   "outputs": [],
   "source": [
    "面积 = width * height"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "120ce396",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "144"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "面积"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9254a54c",
   "metadata": {},
   "source": [
    "* 字符串的方法\n",
    "> 1. str.capitalize():可以将首字母转成大写\n",
    "> 2. str.count():数量？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "ccd7ddf7",
   "metadata": {},
   "outputs": [],
   "source": [
    "name = \"marry\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "9f9e8b23",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Marry'"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.capitalize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "4c98034e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.count(\"r\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "d813f710",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院坐落于广州市从化温泉镇'"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "105f0d40",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.count(\"新媒体\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "d1bdd1de",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['广州南方学院', '广州市从化温泉镇']"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.split(\"坐落于\") #拆分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "525cb27c",
   "metadata": {},
   "outputs": [],
   "source": [
    "text = \"\"\"\n",
    "在2020-2021学年春季学期“朝阳之约”计划晨跑活动中，全体一年级学生积极参与，各院系班级大力支持，展现了南院学子奋发向上、自信昂扬的精神风貌，为表彰先进，树立典范，传承南院学子坚毅勤勉、锐意进取的精神，经研究决定，对“朝阳之约”计划晨跑活动中表现优秀的集体和个人予以表彰：\n",
    "\n",
    "一、决定授予护理与健康学院、云康医学与健康学院、文学与传媒学院、达人书院4个院系，20级护理3班等18个班级2020-2021学年春季学期“晨跑优秀组织奖”。\n",
    "\n",
    "二、决定授予许佳燕等84人2020-2021学年春季学期“晨跑之星”称号。\n",
    "\n",
    "希望受到表彰的集体和个人能够珍惜荣誉，再接再厉。希望完成“朝阳之约”晨跑活动的学生能够继续保持自觉自律、坚持不懈的优良品质，将“朝阳之约”晨跑活动中展现出的精神风貌延续到今后的学习与生活之中，成长为全面发展的优秀人才。\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "6d122807",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['\\n在2020-2021学年春季学期“朝阳之约”计划晨跑活动中，全体一年级学生积极参与，各院系班级大力支持，展现了南院学子奋发向上、自信昂扬的精神风貌，为表彰先进，树立典范，传承南院学子坚毅勤勉、锐意进取的精神，经研究',\n",
       " '，对“朝阳之约”计划晨跑活动中表现优秀的集体和个人予以表彰：\\n\\n一、',\n",
       " '授予护理与健康学院、云康医学与健康学院、文学与传媒学院、达人书院4个院系，20级护理3班等18个班级2020-2021学年春季学期“晨跑优秀组织奖”。\\n\\n二、',\n",
       " '授予许佳燕等84人2020-2021学年春季学期“晨跑之星”称号。\\n\\n希望受到表彰的集体和个人能够珍惜荣誉，再接再厉。希望完成“朝阳之约”晨跑活动的学生能够继续保持自觉自律、坚持不懈的优良品质，将“朝阳之约”晨跑活动中展现出的精神风貌延续到今后的学习与生活之中，成长为全面发展的优秀人才。\\n']"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## 可以搜索停止词字典，进行文本拆分，然后进一步做分析\n",
    "text.split(\"决定\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a4911ce6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
